define(["dojo/_base/declare", "dijit/form/Form", "dijit/form/TextBox", "dijit/form/NumberTextBox", "dijit/form/Button", "dojo/data/ItemFileWriteStore"], function(declare){
    declare("my.form.EditGradeForm", [dijit.form.Form], {
    		startup : function(){
    			dijit.byId("degreeEditIdStudent").attr("disabled", true); 
    			dijit.byId("gradeEditDropDown").attr("disabled", true); 
    			dojo.xhrPost(
    				    {
    				        url : "getCurrentUserAction.action",
    				        handleAs : "json",
    				        load : dojo.hitch(this, this.onLoadCurrentUser),
    				    });
    		},
    		
    		onLoadCurrentUser : function(responseObject, ioArgs){
    			var classesStore = new dojo.data.ItemFileWriteStore(
    		    	    {
    		    	    	url:'getTeacherClassesAction.action?teacher.id='+responseObject.user.id,
    		 			    requestMethod : "post"
    		    	    });
    			
    			var classesDropDown = dijit.byId("degreeEditIdClasses");
    			classesDropDown.set("store",classesStore);
    			
    			dojo.connect(classesDropDown, "onChange", this, function(){
    				dijit.byId("gradeEditDropDown").attr("disabled", true);
    				var classesDropDown = dijit.byId("degreeEditIdClasses");
    				var studentStore = new dojo.data.ItemFileWriteStore(
        		    	    {
        		    	    	url:'getStudentsInClassesAction.action?classes.id='+classesDropDown.get("value"),
        		 			    requestMethod : "post"
        		    	    });
    				var studentsDropDown = dijit.byId("degreeEditIdStudent");
    				studentsDropDown.set("disabled", false);
    				studentsDropDown.reset();
    				studentsDropDown.set("store",studentStore);
    				
    				dojo.connect(studentsDropDown, "onChange", this, function(){
    					var studentsDropDown = dijit.byId("degreeEditIdStudent");
    					var gradeEditStore = new dojo.data.ItemFileWriteStore({
    						url:'getDegreesForStudentAction.action?classes.id='+classesDropDown.get("value")+"&student.id="+studentsDropDown.get("value"),
    		 			    requestMethod : "post"
    					});
    					var gradesDropDown = dijit.byId("gradeEditDropDown");
    					gradesDropDown.set("disabled", false);
    					gradesDropDown.reset();
    					gradesDropDown.set("store", gradeEditStore);
    				});
    				
    			});
    			
    			
    			
    		}

    		
    		
    });
});